from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, DateTime
import datetime

from util.StoreUtil import DBbase

Base = declarative_base()


class IpPool(Base):
    # 表的名字:
    __tablename__ = 'ip_pool'

    # 表的结构:
    id = Column(Integer, primary_key=True, autoincrement=True)
    address = Column(String(30))
    createtime = Column(
        DateTime, default=datetime.datetime.now, comment='创建时间')

    def add(self, session):
        session.add(self)
        session.commit()
        session.close()


if __name__ == "__main__":
    db = DBbase()
    db.get_session()
    Base.metadata.create_all(db.engine)
    new_ip = IpPool(address="192.168.1.1:443")
    db.session.add(new_ip)
    db.session.commit()
    db.session.close()
